package cn.zl.springbootredis.jedis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

/**
 * @Description:测试key
 * @Author: zhanglang
 * @Date: 2020/9/7 10:32
 */
public class TestKey {
    private Jedis jedis;

    @Before
    public void before(){
        this.jedis = new Jedis("192.168.139.188",6379);
    }

    @After
    public void after(){
        jedis.close();
    }

    //测试key相关
    @Test
    public void testKeys(){
//        jedis.del("name","age");//删除多个key
        jedis.del("name");//删除单个key

        //判断一个key是否存在
        Boolean name = jedis.exists("name");
        System.out.println(name);

        //设置一个key超时时间
        Long age = jedis.expire("age", 100);
        System.out.println(age);

        //查看一个key的超时时间
        Long age1 = jedis.ttl("age");
        System.out.println(age1);

        //随机获取一个key
        String s = jedis.randomKey();
        System.out.println(s);

        //修改key的名称
        String rename = jedis.rename("name", "newName");
        System.out.println(rename);

        //查看对应值的类型
        String name1 = jedis.type("name");
        System.out.println(name1);

    }
}
